<template>
  <div class="discovery-container">
    <!-- 轮播图 -->
    <el-carousel :interval="4000" type="card" height="200px">
       <el-carousel-item v-for="item in banners" :key="item" >
         <img :src="item.imageUrl" alt="">
       </el-carousel-item>
   </el-carousel>
    <!-- 推荐歌单 -->
    <div class="recommend">
      <h3 class="title">
        推荐歌单
      </h3>
      <div class="items">
        <div class="item" v-for="(k,index) in list" :key="index" @click="toPlaylist(k.id)">
          <div class="img-wrap">
            <div class="desc-wrap">
              <span class="desc">{{k.copywriter}}</span>
            </div>
            <img :src="k.picUrl" alt="" />
            <span class="iconfont icon-play"></span>
          </div>
          <p class="name"> {{k.name}} </p>
        </div>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="news">
      <h3 class="title">
        最新音乐
      </h3>
      <div class="items">
        <div class="item" v-for="(k,index) in songs" :key="index">
          <div class="img-wrap">
            <!-- 封面 -->
            <img :src="k.picUrl" alt="" />
            <span class="iconfont icon-play" @click="playMusic(k.id)"></span>
          </div>
          <div class="song-wrap">
            <!-- 歌名 -->
            <div class="song-name">{{k.name}}</div>
            <!-- 歌手名 -->
            <div class="singer">{{k.song.artists[0].name}}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐MV -->
    <div class="mvs">
      <h3 class="title">推荐MV</h3>
      <div class="items">
        <div class="item" v-for="(k,index) in mvs" :key="index" @click="toMV(k.id)">
          <div class="img-wrap">
            <img :src="k.picUrl" alt="" />
            <span class="iconfont icon-play"></span>
            <div class="num-wrap">
              <div class="iconfont icon-play"></div>
              <!-- 播放次数 -->
              <div class="num">{{k.playCount}}</div>
            </div>
          </div>
          <div class="info-wrap">
            <!-- mv名 -->
            <div class="name">{{k.name}}</div>
            <!-- 歌手名 -->
            <div class="singer">{{k.artists[0].name}}</div>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      banners:'',
      list:[],
      songs:[],
      mvs:'',
      url:''
    }
  },
  created(){
    //2022/12/20
    //轮播图接口
   this.axios.get('banner')
    .then(res=>{
      this.banners = res.data.banners
    })
    //推荐歌单
    this.axios.get('personalized',{
      params:{
        //条数
        limit:10
      }
    })
    .then(res=>{
      this.list = res.data.result
    })
    //最新音乐
    this.axios.get('personalized/newsong')
    .then(res=>{
      this.songs=res.data.result
     // console.log(this.songs);
    })
    //最新mv
     this.axios.get('personalized/mv')
     .then(res=>{
       console.log(res);
       this.mvs=res.data.result
        //console.log(this.mvs);
     })
  },
  methods: {
    playMusic(id){
      this.axios.get('song/url',{
        params:{
          id
        }
      })
      .then(res=>{
         this.url = res.data.data[0].url
         console.log( this.url);
         //传给父组件的播放地址
        this.$emit("srcChange",this.url)
      })
    },
    toPlaylist(id){
      this.$router.push(`/playlist?id=${id}`)
    },
    toMV(id){
      this.$router.push(`/mv?id=${id}`)
    }
  },
}
</script>

<style>

</style>